package com.lagou.homeWork3.hw5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HomeWork5 {
    //按大小的顺序存放牌数
    private static String[] value = { "大王", "小王", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
    //存放花色
    private static String[] type = {"♥","♦","♠","♣"};
    //用来接收配好花色的牌和大小顺序
    private static Map<Integer, String> cards = new HashMap<>();
    //用来存放1-54的集合，用来打乱顺序
    private static List<Integer> order = new ArrayList<>();
    //用来存放玩家手里的牌和底牌
    private static List<Integer> a = new ArrayList<>();
    private static List<Integer> b = new ArrayList<>();
    private static List<Integer> c = new ArrayList<>();
    private static List<Integer> d = new ArrayList<>();


    //给Map集合里放入组合好的牌和大小顺序
    public static void getCards() {
        //用来排序
        int index = 1;
        //循环牌的数字
        for (int i = 0; i < value.length; i++) {
            //循环花色，并将花色和数字组合到一起，放进Map
            for (int j = 0; j < type.length; j++) {
                //大小王没有花色
                if (i < 2) {
                    cards.put(index, value[i]);
                    order.add(index);
                    index++;
                    break;
                } else {
                    cards.put(index, type[j] + value[i]);
                    order.add(index);
                    index++;

                }
            }

        }
    }
    
    //打乱顺序
    public static void shuffle(){
        Collections.shuffle(order);
    }
    
    
    //发牌，和底牌
    public static void sendCard(){
        for (int i = 0; i < order.size(); i++) {
            int cardId = order.get(i);
            if(i<3){
                d.add(cardId);
            }
            else if (i%3==1) {
                a.add(cardId);
            }else if(i%3==2){
                b.add(cardId);
            }else{
                c.add(cardId);
            }
        }
        Collections.sort(a);
        Collections.sort(b);
        Collections.sort(c);
    }

    //从集合中拿到各自的牌
    private static void printCards(List<Integer> i){
        for (Integer integer : i) {
            System.out.print(cards.get(integer)+" ");
        }

    }


    //显示所有牌
    public static void showCards(){
        System.out.println("a玩家：");
        printCards(a);
        System.out.println("\nb玩家：");
        printCards(b);
        System.out.println("\nc玩家：");
        printCards(c);
        System.out.println("\n底牌：");
        printCards(d);

    }
}
